﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;

namespace Besture.Common.Helper
{
    public class FunHelper
    {
        #region 页面提示-跳转

        /// <summary>
        /// 直接返回
        /// </summary>
        public static void Back()
        {
            HttpContext.Current.Response.Write("<script language='JavaScript'>");
            HttpContext.Current.Response.Write(" history.go(-1);");
            HttpContext.Current.Response.Write("</script>");

        }

        /// <summary>
        /// 提示后返回
        /// </summary>
        /// <param name="str"></param>
        public static void Back(string str)
        {
            HttpContext.Current.Response.Write("<script language='JavaScript'>");
            if (str != null)
            {
                HttpContext.Current.Response.Write(" alert('" + str + "');");
            }
            HttpContext.Current.Response.Write(" history.go(-1);");
            HttpContext.Current.Response.Write("</script>");

        }

        /// <summary>
        /// 提示
        /// </summary>
        /// <param name="str"></param>
        public static void Alert(string str)
        {
            HttpContext.Current.Response.Write("<script language='JavaScript'>");
            HttpContext.Current.Response.Write("alert('" + str + "');");
            HttpContext.Current.Response.Write("</script/>");
        }

        public static void Alert(Page p, string pText)
        {
            p.RegisterStartupScript("message", "<script type='text/javascript'>alert('" + pText + "')</script>");
        }

        /// <summary>
        /// 页面提示
        /// </summary>
        /// <param name="str"></param>
        public static void ScriptAlert(string str)
        {
            ClientScriptManager JsManager = ((Page)HttpContext.Current.Handler).ClientScript;
            JsManager.RegisterStartupScript(JsManager.GetType(), "myscript", "<script>Alter('" + str + "');</script>");
            return;
        }

        /// <summary>
        /// 提示后跳转到url页面
        /// </summary>
        /// <param name="str"></param>
        /// <param name="url"></param>
        public static void Alert(string str, string url)
        {
            HttpContext.Current.Response.Write("<script language='JavaScript'>");
            if (str != null)
            {
                HttpContext.Current.Response.Write(" alert('" + str + "');");
            }
            if (url != null)
            {
                HttpContext.Current.Response.Write(" location.href='" + url + "';");
            }
            HttpContext.Current.Response.Write("</script>");
        }

        /// <summary>
        /// 提示后关闭
        /// </summary>
        /// <param name="str"></param>
        public static void AlertClose(string str)
        {
            HttpContext.Current.Response.Write("<script language='JavaScript'>");
            HttpContext.Current.Response.Write("alert('" + str + "');window.opener=null;window.close();");
            HttpContext.Current.Response.Write("</script/>");
        }

        #endregion
    }
}
